#!/bin/sh
###################
source /etc/profile
source /root/.bash_profile
##################
cd `dirname $0`
#质量报告诊报告学院/课程/专业/教师/学生层面数据项定时脚本 学年

#所执行的脚本学院层面
REPORT_COLLEGE=qu_college_student_quality_report.sh
#所执行的脚本学院层面（里面的方法）
SHELL_COLLEGE="
Number_of_staff
Number_of_Counselors
Counselor_student_teacher_ratio
Full_time_teachers_are_high
Deputy_Senior_Teacher
The_proportion_of_full_time_teachers_above_deputy_senior
Teachers_with_postgraduate_education_or_above
The_proportion_of_teachers_with_postgraduate_education_or_above
Double_qualified_teachers
The_proportion_of_teachers_with_double_qualifications
Number_of_enrollment_Majors
Quantity_of_three_year_Majors
Major_categories
Large_class_quantity
Name_of_Secondary_Colleges_and_Departments
Coefficient_Quantity_of_Secondary_College
Number_of_tasks_completed
Task_completion_rate
"
#所执行的脚本课程层面
REPORT_COURSE=qu_course_quality_report.sh
#所执行的脚本课程层面（里面的方法）
SHELL_COURSE="
import_table_MBDCLCGBFZJSZKDSL
import_table_BZDCLCGBFZJSZKDSL
"
#所执行的脚本专业层面
REPORT_MAJOR=qu_major_quality_report.sh
#所执行的脚本专业层面（里面的方法）
SHELL_MAJOR="
Number_enrollment_Majors
Name_of_Department
Number_of_Department
Names_of_Professional_Categories
Large_class_quantity
Apprentice_major
Number_National_Key_Specialties
Number_Provincial_key_points
import_table_DSJZDZY
Number_school_level_points
Number_National_Key_characteristic
Number_Provincial_key_characteristic
import_table_DSJTSZY
Number_school_level_characteristic
import_table_MBDCLCGBFZJSZKDSL
import_table_BZDCLCGBFZJSZKDSL
"
#所执行的脚本学生层面
REPORT_STUDENT=qu_student_quality_report.sh
#所执行的脚本学生层面（里面的方法）
SHELL_STUDENT="
Number_of_full_time_Counselors
Number_of_part_time_Counselors
Counselor_student_teacher_ratio
Postgraduate_degree_or_above_accounted_for
Goal_Achievement_Rate_Over_nine_Quantity
Standard_Achievement_Rate_Over_nine_Quantity_Quantity
"

#所执行的脚本教师层面
REPORT_TEACHER=qu_teacher_quality_report.sh
#所执行的脚本教师层面（里面的方法）
SHELL_TEACHER="
import_table_ZRJSSL
import_table_ZGZCRS
import_table_FGZCRS
import_table_FGYSZZRBL
import_table_YJSYSRS
import_table_YJSYSRSJZRBL
import_table_SSSZJSRS
import_table_SSSZJSRSZZRJSBL
import_table_XWJZJSRS
import_table_XWJZJZGRS
import_table_XWJZJFGRS
import_table_XWJZJFGJYSRS
import_table_XWJZJSYJSYSXLJSRS
import_table_XWJZYJSZJZSBL
import_table_JSCMMBDCLCGBFZJSDZKDSL
import_table_JSCMBZDCLCGBFZJSDZKDSL
"

#日志路径
function getRunLogPath(){
    datetime=$(date --date "0 days ago" +%Y%m%d)
    if [ ! -d "./logs" ];then
        mkdir ./logs
    fi
    LOG_RUN_PATH=/root/etl/SXNYZY/Timing/qualityreport/logs/$0_${datetime}.log
}

function doconmand(){
    start=$(date +%s)
    #读取文件的每一行
	for comand in ${comands}
	do
		ps -ef|grep $comand|grep -v grep|cut -c 9-15|xargs kill -9
        sh $REPORT "${comand}"
        end=$(date +%s)
		 if [ $? -eq 0 ]; then
	    	echo " $comand succeed>>>  耗时$(( $end - $start ))s " >>  ${LOG_RUN_PATH} 2>&1
		 else
		    echo " $comand failed>>>  耗时$(( $end - $start ))s "  >>  ${LOG_RUN_PATH} 2>&1;
		    echo " ## sh $comand 脚本执行错误，退出命令  exit 1  ##"  >>  ${LOG_RUN_PATH} 2>&1;
		    exit 1;
		 fi

	done
	end=$(date +%s)
	echo " 耗时$(( $end - $start ))s" >>  ${LOG_RUN_PATH} 2>&1
	#删除脚本执行过程中产生的Java文件
	rm -rf *.java
}


#学院层面
function docollege() {
   echo "-------学院层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1
   comands=${SHELL_COLLEGE[*]}
   REPORT=${REPORT_COLLEGE}
   doconmand
}

#课程层面
function docourse() {
   echo "-------课程层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1
   comands=${SHELL_COURSE[*]}
   REPORT=${REPORT_COURSE}
   doconmand
}

function domajor() {
   echo "-------专业层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1
   comands=${SHELL_MAJOR[*]}
   REPORT=${REPORT_MAJOR}
   doconmand
}

function dostudent() {
   echo "-------学生层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1
   comands=${SHELL_STUDENT[*]}
   REPORT=${REPORT_STUDENT}
   doconmand
}

function doteacher() {
   echo "-------教师层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1
   comands=${SHELL_TEACHER[*]}
   REPORT=${REPORT_TEACHER}
   doconmand
}

getRunLogPath
echo "日志路径:"$LOG_RUN_PATH
currentPath=/root/etl/SXNYZY/QualityReport
echo "脚本路径:"$currentPath
comands=()
comands_twos=()


if [ $? -eq 0 ]; then
	cd  $currentPath/college
	docollege
fi

if [ $? -eq 0 ]; then
	cd  $currentPath/course
	docourse
fi

if [ $? -eq 0 ]; then
	cd  $currentPath/major
	domajor
fi

if [ $? -eq 0 ]; then
	cd  $currentPath/student
	dostudent
fi

if [ $? -eq 0 ]; then
	cd  $currentPath/teacher
	doteacher
fi

echo "*********所有脚本执行完毕*********" >>  ${LOG_RUN_PATH} 2>&1

